<?php
/**
 * @author Laurent SITTLER <lolo.sittler@gmail.com>
 * @author Alexandre GOMEZ <gomez.alexandre02@gmail.com>
 * @version 0.1
 */
require_once 'Library/Ariane.php';
require_once 'Library/Tab.php';
require_once 'Library/ContentTab.php';
require_once 'Model/Database_Model.php';
require_once 'Model/Informations_Model.php';

/**
 *  Master Page (PHP or SMARTY)
 */
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <!--[if lt IE 9]>
            <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <title>sgbdMyAdmin</title>

        <link rel="icon" href="<?php echo $GLOBALS['conf']['interface']['url']; ?>Public/images/favicon.ico" type="image/x-icon" />
        <link rel="shortcut icon" href="<?php echo $GLOBALS['conf']['interface']['url']; ?>Public/images/favicon.ico" type="image/x-icon" />

        <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['conf']['interface']['url']; ?>Public/css/default.css"/>
        <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['conf']['interface']['url']; ?>Public/css/jquery-ui-1.9.2.custom.css" />
        <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['conf']['interface']['url']; ?>Public/css/jquery.snippet.css" />
        <script type="text/javascript" src="<?php echo $GLOBALS['conf']['interface']['url']; ?>Public/js/jquery-1.8.3.js"></script>
        <script type="text/javascript" src="<?php echo $GLOBALS['conf']['interface']['url']; ?>Public/js/jquery-ui-1.9.2.custom.js"></script>
        <script type="text/javascript" src="<?php echo $GLOBALS['conf']['interface']['url']; ?>Public/js/textarea_lined.js"></script>
        <script type="text/javascript" src="<?php echo $GLOBALS['conf']['interface']['url']; ?>Public/js/popup.js"></script>
        <script type="text/javascript" src="<?php echo $GLOBALS['conf']['interface']['url']; ?>Public/js/smartpaginator.js"></script>
        <script type="text/javascript" src="<?php echo $GLOBALS['conf']['interface']['url']; ?>Public/js/jsapi.js"></script>
        <script type="text/javascript" src="<?php echo $GLOBALS['conf']['interface']['url']; ?>Public/js/jquery.snippet.js"></script>
    </head>
    <body>
        <?php
        // Include popup info
        include 'popup_info.php';
        ?>
        <!-- Menu left -->
        <nav id="navLeft">
            <!-- Logo -->
            <img src="<?php echo $GLOBALS['conf']['interface']['url']; ?>Public/images/SGBDMyAdmin.png" title="" id="logo"/>
            <div id="title"><span>SGBD</span>MyAdmin</div>
            <!-- Menu rapide -->
            <div id="speedLink">
                <a href="<?php echo $GLOBALS['conf']['interface']['url']; ?>index/home" title="Accueil" class="home">&nbsp;</a>
                <a href="<?php echo $GLOBALS['conf']['interface']['url']; ?>index/logout" title="Se déconnecter" class="disconnect">&nbsp;</a>
                <button id="open-message" class="help">&nbsp;</button>
            </div>
            <!-- Liste des bases de données de l'utilisateur -->
            <?php
            include 'popup_db.php';
            $dbUser = new Database_Model();
            $dbUser->GetDB(Session::Get(Constants::$SESSION_cuser));
            ?>
        </nav>
        <section id="sdefault">
            <header>
                <?php
                $ariane = new Ariane();
                $ariane->Show();
                ?>
            </header>
            <article>
                <div id="tabs">
                    <ul>
                        <?php
                        $infoTabs = new Informations_Model();
                        $tabs = $infoTabs->GetTabs();
                        $content = $infoTabs->GetContentTabs($tabs);
                        foreach ($tabs as $tab) {
                            echo '<li><a href="#tabs-' . $tab->GetPage() . '" class="myTabs"><span class="' . $tab->GetIcon() . '">&nbsp;</span>' . $tab->GetName() . '</a></li>';
                        }
                        echo '</ul>';
                        echo '<br />';
                        if (Session::Get(Constants::$SESSION_error) != NULL) {
                            echo '<div class="ui-widget" id="merror">';
                            echo '<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">';
                            echo '<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>';
                            echo '<strong>Erreur : </strong><br />' . utf8_encode(Session::Get(Constants::$SESSION_error)) . '</p>';
                            echo '</div>';
                            echo '</div> ';
                        }

                        // Si un message de validation existe
                        if (Session::Get(Constants::$SESSION_valid) != NULL && Session::Get(Constants::$SESSION_error) == NULL) {
                            echo '<div class = "ui-widget" id="mvalid">';
                            echo '<div class = "ui-state-highlight ui-corner-all" style = "margin-top: 20px; padding: 0 .7em;">';
                            echo '<p><span class = "ui-icon ui-icon-info" style = "float: left; margin-right: .3em;"></span>';
                            echo '<strong>Succès : </strong><br />' . Session::Get(Constants::$SESSION_valid) . '</p>';
                            echo '</div>';
                            echo '</div>';
                        }
                        $j = 1;
                        foreach ($content as $ContentTab) {
                            $inc = 'View/' . $ContentTab->GetName() . '.php';
                            if (file_exists($inc)) {
                                echo '<div id="tabs-' . $ContentTab->GetId() . '">';

                                // Si un message d'erreur existe
                                $oldTab = 0;
                                if (Session::Get(Constants::$SESSION_currentTabs) != NULL)
                                    $oldTab = Session::Get(Constants::$SESSION_currentTabs);

                                echo '<input type="hidden" id="oldTab" value="' . $oldTab . '"/>';
                                // Inclus la vue
                                include($inc);
                                echo '</div>';
                            }
                            $j = $ContentTab->GetId() + 1;
                        }
                        ?>
                </div>
            </article>
            <footer id="fdefault">
                coryright 2013 &copy; ITII/CNAM Alsace | Laurent SITTLER - Alexandre GOMEZ :)
            </footer>
        </section>
        <script type="text/javascript">
            $(document).ready(function() {
                $("#tabs" ).tabs();
                $("#tabs").tabs('select', $("#oldTab").val());
                // Auto Resize onload
                autoResize();
                // On click Tab
                $(".myTabs").click(function(){
                    autoResize();
                    hideMessages();
                });
            });
            
            // Auto resize left menu
            function autoResize(){
                if ($("#sdefault").height() > $(window).height()){
                    $("#navLeft").css("height",  $("#sdefault").height());
                }
                else{
                    $("#navLeft").css("height", "100%");
                }
            }
            
            // Hide message
            function hideMessages(){
                $("#merror").hide();
                $("#mvalid").hide();
            }
        </script>
    </body>
</html>
